package com.axjy.base.service.impl;

import com.axjy.base.feign.ItemFeignClient;
import com.axjy.base.mapper.ImageMapper;
import com.axjy.base.service.ImageService;
import com.axjy.base.vo.BannerVo;
import com.axjy.comm.pojo.TpImage;
import com.axjy.comm.pojo.TpItem;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

@Service("imageService")
public class ImageServiceImpl implements ImageService {

    @Resource
    private ImageMapper imageMapper;

    @Resource
    private ItemFeignClient itemFeignClient;


    @Override
    public List<BannerVo> searchBannerList() {
        QueryWrapper<TpImage> wrapper= Wrappers.<TpImage>query();
        wrapper.eq("type",1);
        List<TpImage> list=  imageMapper.selectList(wrapper);
        List<BannerVo> voList=list.stream().map(tpImage -> {
            BannerVo vo=new BannerVo();
            vo.setId(tpImage.getId());
            vo.setTargetId(tpImage.getTargetId());
            TpItem tpItem=itemFeignClient.findById(vo.getTargetId());
            vo.setItemName(tpItem.getItemName());
            vo.setMinPrice(tpItem.getMinPrice());
            return vo;
        }).collect(Collectors.toList());
        return voList;

    }
}
